Get the server variable from ASP.Net

It is very often a developer or programmer want to know the system/server variable of a server that without their right to access to the server back-end.

With ASP.Net, you could get the server variable through scripting.

When you need these information from your IIS based server, create a aspx file named variable and place the script as below based on C# or VB.

VB

<% @ Page Language="VB" %>
<%
For Each var as String in Request.ServerVariables
Response.Write(var & " " & Request(var) & "<br>")
Next
%>

C#

<% @ Page Language="C#" %>
<%
foreach (string var in Request.ServerVariables)
{
  Response.Write(var + " " + Request[var] + "<br>");
}
%>

Well Done, hope this is useful for the programmer.

Understand ASP.Net custom error

It is very normal when you design your script in ASP.Net and getting some runtime error as attached below when you are designing your script from your local PC and uploaded to the web server.

With the above error, some programmer not even know what to do :S .

Today, MGe will guide you on what is the custom Error type and how to make it work when you are hosted to the web server that do not have the administrator privilege.

Basically custom error used to hide the real error from the script from the visitor, where it might be the sensitive information from your website such as connection string.

The ASP.Net <customErrors /> do have 3 types, such as On, Off and RemoteOnly. In short, may refer to the table as below.

Off Show everyone the detailed error message.  This is rarely a good idea.
On Don’t show anyone the detailed error message.
RemoteOnly Only show the detailed error message if you are testing from the local server where the site resides.

To set it, just open your web.config file and set it from the <system.web>.

Eg.

<customErrors mode="RemoteOnly" />

VI Editor

The VI editor is screen-based editor used by many Linux users. The VI editor is designed through C programming and it is useful to aid programmer.

To start using the vi editor, simply type “vi” from the terminal and this will allow you to enter the vi editor. If you are opening a file, you shall see the status as below.
“filename” 1 lines, 1 characters

If you are creating a new file, you will see the following status.
“filename” [New file]

To exit from vi editor, you should press Esc or ^] (control + ]) then enter :q to exit. Sometimes, you have modified something but do not want to save it, you may use :q! command.

If you have modified some script and want to save it, use :wq to save it or you may use the short-cut key of ZZ.

To understand more, refer to the image as below.

Jailed Shell memory issue

If you are using Secure Shell (SSH), you might get these error when you running your php script.

PHP Fatal error:  Out of memory (allocated 20447232) (tried to allocate 4096 bytes) in email.php

If you are the programmer or system administrator, you might tried to increase the memory_limit from the php.ini or using ini_set to increase the memory_limit but you will find out no matter how much memory_limit you set will not solve the problem.

The reason of the error occurs is not because of the PHP memory_limit usage of your script, but it is because the jailed shell limitation.

With cPanel jailed shell, the problem could caused by the forkbomb setting of your cPanel limited the PHP memory.

You may easily get this fix by modify the file as detail below where you should change the user to the cPanel user of your account.
/home/virtfs/user/etc/profile.d/limits.sh

Search for,
if [ “$LIMITUSER” != “root” ]; then

Then modify the ulimit “-m 200000” to “-m unlimited” and save it.

Using URLRewrite mappings in separate file

Nowadays, Programmer rarely know that .Net Framework could actually do the rewrite through the .Net URL Rewrite itself without using the third-party application to call the .htaccess rules from Apache and do not need to use APE to run the rules.

But do you know that with URL Rewrite rules that applied to the web.config file, you could actually call it externally without messed up such as the .htaccess.

By right, the format of the URL rewrite rules could as simply as below.

<rewriteMaps>
<rewriteMap name=”Redirects”>
<add key= “/ oldurl” value=”/newurl” />
<add key= “/ otheroldurl” value=”/othernewurl” />
</rewriteMap>
</rewriteMaps>

You could applied the above rules to your web.config file, however you could do the below calling function from external file.
<rewriteMaps configSource=”rewritemaps.config” />

We named the another file called rewritemaps.config, and you may applied all of the rewrite rules over there.