Error When running asp.net Application in IIS - asp.net

I have an application in asp.net.I configured it in IIS.When i running this application in IIS i getting an error;
Server "/" error:
Resource Cannot be Found
Error:404
Some of pages only produce this issues.Other forms are working perfectly.Without running application in IIS Its working perfectly.
If any one can answer plz send the answer immediatly.
Thank you

I assume that the urls for some of your pages are malformed.
Check in your app how you are building the paths.
Personally, i use to have a class like PathsUtil, where i build all of my paths for the pages,
so when i'm moving to IIS, it's extremely easy just to correct something (for instance add a virtual dir etc).
Update:
- for the PathsUtil i use Paths.resx where i have defined all of my paths like
Name Value
index /Site/index.aspx
add.user /Site/addUser.aspx
and so on.
And in PathsUtil i only take the value from the Paths.resx and i build the url:
string baseUrl = getBaseUrl() + (String)HttpContext.GetGlobalResourceObject("Paths", "index");
I've just moved to an IIS7 server, and there i've created a virtual dir "gramma"
You can note that was a piece of cake only to add "/gramma" in Paths.resx, in front of each url :)

Look for the Response.Redirect() calls in the page previous to the form you are getting the error. Just make sure that any harcoded URL for the form supplied to the Response.Redirect() call is correct.
EDIT..
Also, look for If you are navigating to a form which is in a different directory than the current one. For example:-
Response.Redirect("../SomeForm.aspx");
will redirect to an ASPX page just one level up of the current one. Each pair of dots implies one directory level up.
In thses cases, I think, you are better off using ~ (tilde) character which will always take the path from the root. So the mistakes happening because of incorrect number of dots can be minimised.Try something like this:-
Response.Redirect( this.ResolveUrl("~/Myfolder/SomeForm.aspx") );
More details for the ~ and ResolveUrl here.
This can also happen If you have window.location calls in javascript if you assign an incorrect URL to the same.

Related

URL redirecting in classic asp

My application url is like this.
http://somename/webname/default.asp
It also contains some other default.asp like http://somename/webname/booking/default.asp and some others too. Even if user tries to access other default.asp, I want them to redirect to
http://somename/webname/default.asp.
Update:
I have been checking like this in global.asa.
Application("txtPathInfo") = Request.ServerVariables("PATH_INFO")
if (Application("txtPathInfo") <> "/webname/default.asp") then
Response.Redirect("/webname/default.asp")
end if
But the problem is, first time it is working fine,redirecting to desired page. Next attempt it allows, may be the global.asa is not called while trying to access in same session. Please anyone provide some feasible solution on this. Thanks :)
One quick way is to put this code in a default.asp page in each possible folder.
<%
Response.Redirect "http://somername/default.asp"
%>
If there are too many folders or some of those folders don't physically exist you'll need to use a url rewrite rule or code within a custom 404 error page.
For rewrite rules this will depend on which version of IIS you are running. If IIS6 then I'd recommend IIRF but if you're running IIS7 or IIS8 then use the built in url rewrite module (installed via Web Platform Installer).

Single Page ASP application and Routing

I thought this would be very simple but it's proved difficult to find the information I'm looking for online... I have a single page website using ASP and I want to use query strings but I don't want to have to put Default.asp in the URL. So at the moment the URL would be something like:
http://localhost/default.asp?id=4
But I'd like something like:
http://localhost/watch?id=4
I'm not using Visual Studio so was hoping to be able to do this with a simple text editor. I'm not that familiar with ASP either so this I'm very much a newbie with these concepts.
You have 2 options.
1: Use URLRewrite extension from Microsoft that can be found here
You can set-up an inbound rule for the pattern: watch using wildcards, and add conditions that disable the rule when a file or directory actually exists. (URL Rewrite sets this by default), then create your action to point to default.asp and check the Append query string box. Then it will route all /watch url's to your default.asp page and will allow your script to read all querystrings as it does normally.
2: Use a custom 404 error page:
Point your error 404 page to the default.asp page in IIS, but you will need to use Request.ServerVariables("Querystring") to parse out the actual URL requested, since the 404 error page is not able to get your querystring by using Request.Querystring as you will be able to do in option 1. You will have to create your own url reading system, since the data returned as the querystring would be something like ?404;http://www.domain.com/watch?id=12312, instead of ?id=12312 like it would in option 1.
Personally I would use the 1st option, even though it requires to install the extension, it's more flexible and doesn't fill up the logs with 2 seperate requests like option 2 does, and its just more transparent to your script rather than creating your own url reading system as you would have to using option 2.

Change the broswer's address name

how can I change the broswer's address name?? For example I have this: www.example.es/Pages/site.aspx and I want this: www.example.es/site
How can I do that?? Ty.
you can use the 404 error challenge and Server.transfer() to do URL rewriting using classic asp
Things you need
How to create a custom 404 page
Regular expression pattern to recreate actual file path or a predefined list
eg:-www.example.com/pg1/ ---> /pages/pg1.asp
Simple server.transfer() to handle valid / invalid server requests.
<%
IF Request.ServerVariables("SCRIPT_NAME") = "pg1" THEN
Server.transfer("/pages/pg1.asp")
ELSE
Response.write("404 - Page not found");
END IF
%>
that's all you are doing basic level URL rewriting using classic asp.
Your question asks about .aspx (asp.net) pages, but your question is tagged asp-classic... you will get better responses to future questions by using the correct tag.
In this case: as long as you can install a module on your server, and you're server can process ASP.Net's web.config files, you can use the IIS URL Rewrite module that Graham mentioned in the comments. I've got an old ASP-Classic site that uses the module just fine.
If you can install an extension, you could also use Ionics Isapi Rewrite Filter. Some hosts have this installed already.
All things being equal, if you have the ability to run your choice, I'd go with the IIS URL Rewrite Module as I've generally seen better performance from it. But that may just be me.
If you do not have that kind of access to the server, and there's not something already installd, you may have to go with the 404 mapping Jeevaka Nuwan Fernando mentions.
There are some other options, but they depend on if you are using ASP.Net or ASP-Classic.

Possible bug/issue in ASP.NET 3.5 related to Request.RawUrl property

I posted a query for 301-redirect using ASP.NET 3.5 here:
Redirecting default.aspx to root virtual directory
Based on the replies I got there, I realized there might be a bug in ASP.NET's Request.RawUrl method which is unable to return the actual raw url (without /default.aspx) when being used in a sub-directory, i.e. the /default.aspx page is inside a subdirectory.
Can someone please shed some light on this possible bug?
Thanks,
Asif
i found a good explanation here
http://codeasp.net/blogs/vivek_iit/microsoft-net/873/301-redirect-from-default-aspx-to-site-root
Thanks
If you suspect this is a bug, then the place to go is Microsoft Connect, where you can report and discuss the bug directly with Microsoft.
Edit: I was able to reproduce the look per your comments.
I was unable to reproduce the infinite loop, however. I injected code into the Global.asax Application_BeginRequest handler of a web application and got the expected behavior of a single redirect.
There are other, and IMO much better, options for handling global redirect rules. On IIS7, I use the URL Rewrite module to configure rewrite rules in IIS. You can read more about it and download it here: http://www.iis.net/download/urlrewrite. The appeal of a solution such as this is that you can customize and update your rewrite rules without recompiling the application.
Edit: I was able to retrieve the raw URL without the default.aspx (after the redirect) by using instead:
Request.ServerVariables["CACHE_URL"]
It's worth a shot.
Have you looked at the IIS settings for your virtual directory? If there is a default document set to default.aspx then this will explain the infinite loop that you are experiencing. You are telling the website to redirect to the virtual directory without the "default.aspx" and IIS is detecting this on the next request and putting it back in ad infinitum.
Right click your virtual directory, select Properties and then the Documents tab. If default.aspx is in the list then that is what you will get. The Url of the request will be passed to the ASP.NET worker process as /folder/default.aspx rather than /folder/
This is not a bug. If IIS didn't do this, you would get a page not found error.
Sounds to me like you need to investigate URL rewriting: http://msdn.microsoft.com/en-us/library/ms972974.aspx

Web.Routing for the site root or homepage

I am doing some work with Web.Routing, using it to have friendly urls and nice Rest like interfaces to a site that is essentially rendered by a single IHttpHandler. There are no webforms, the handler generates all the html/json and writes it as part of process request.
This works well for things like /Sites/Accounting for example, but I can't get it to work for the site root, i.e. '/'.
I have tried registering a route with an empty string, with 'default.aspx' (which is the empty aspx file I keep in my root folder to play nice with cassini and iis). I set RouteExistingFiles to false explicitly, but whatever I do when hitting the root url it still opens default.axpx, which has no code it inherits from, and contains a simple h1 tag to show that I've hit it.
I don't want to change the default file to redirect to a desired route, I just want the equivalent of a 'default' route that is applied when no other routes are found, similar to MVC.
For reference, the previous version of the site didn't use Web.Routing, but had a handler referenced in the web.config that was perfectly capable of intercepting requests for the root or default.aspx.
Specs: ASP.NET 3.5sp1, C#, no webforms, MVC or openrasta. Plain old IHttpHandlers.
Fixed my own problem: the issue is the integrated web server, Cassini or some such. Seems that it doesnt play nice with routing, and will by default simply return the default.aspx file or, if it is missing, show a directory listing.
Using IIS with a virtual directory works fine, but is annoying (frustrates code sharers because they need to set up new virtual directories when they open my app, and pollutes my own IIS instance. Bah. Probably what I'll do for the moment however, or setup a new application manually so I can use the domain host only path like what will exist in live.
An alternative is to use the updated version of cassini, seen here, which works if the default.aspx file is missing, but I have not worked out how to integrate it with visual studio yet. Any help would be appreciated, but its not a big priority given I have workarounds.
I realise that this is a really old post, but I just ran into the same problem using VS2012, so I'm posting this here just in case.
I solved the problem by installing IIS Express and setting the project to use IIS Express in Visual Studio. Solved the problem.

Resources