I'm trying to use jQuery to make some AJAX calls, but because I have wild card mapping (to .NET) in IIS 6 turned on, it doesn't seem to work. Disabling the mapping makes everything magically work.
I've put the web method attribute on methods in both an .aspx page and an .asmx web service, but neither work. Here is the sample URL that I am using for the AJAX calls:
localhost/UserChecker.aspx/CheckIfUserEmailsExists
localhost/UserChecker.asmx/CheckIfUserEmailsExists
I figure it must be something with the way .NET is interpreting the URL's but I'm not entirely sure why. More importantly, I'm not sure how to fix it, other than to disable wild card mapping! Is there any other way???
UPDATE
The CMS I am using (Kentico) does some URL routing, but even if I skip over the routing in the global.asax.cs code, I still get a 404.
Thanks in advance!
With the wildcard mapping on IIS will run the initial request via the wildcard handler first. This will be done BEFORE any URL rewriting (or URL routing) by your CMS.
I think that is why you are getting 404.
You can also try to disable "verify file exists" checkbox on the wildcard mapping to cater for the scenario when the actual URL will be later rewritten to something else.
This is not a complete answer but I hope it points you in the direction of a solution.
Have you tried accessing the url directly in a browser and using some well placed breakpoints to track down the problem?
If you're getting 404s it sounds like your rules for routing aren't working.
[I'll update this if you can give a little more info about the behaviour you're seeing]
UPDATE
I think what might be happening is this:
You're providing a seperate mapping for your files with extensions (in these cases .aspx and .asmx):
localhost/UserChecker.aspx/CheckIfUserEmailsExists
localhost/UserChecker.asmx/CheckIfUserEmailsExists
These mappings are being used when you turn the wild card mappings off, and the '/CheckIfUserEmailsExists' is handled used or ignored.
When you turn on the wildcard mappings your routing isn't informing your app how to 'route' correctly.
If you removed the extensions (with wildcard mappings turned on) does the following work?
localhost/UserChecker/CheckIfUserEmailsExists
Add the appropriate URLs to the exclusion list: Use the "Excluded URLs" setting in the Site Manager->Settings tab. (basic help documentation)
I suggest checking the URl outside of your CMS framework; Issue has to be with the URL routing. No tsure how it was working without the wild card mapping.
Questions to understand:
1.Did you have your CMS running when trying without wild card mapping?
2. How does this CMS system interact with IIS; IASPI dll ? or HTTP Handlers/modules?
Related
I'm pretty inexperienced when it comes to working with IIS, so I apologize if the question is a bit confusing.
In the application, I have a Controller with a method called 'Login' that takes in a string parameter. The parameter identifies the organization the user is trying to authenticate against.
For example:
http://mysite1.com/Login/12345
Visiting this link brings the user to a login page for the organization that is associated with '12345' for their access key.
Is there any way to redirect users that are logging in under '12345' to another server? We have a few beta users that are willing to participate, but the database schemas for both servers are different, so it's important that the beta users are not hitting the wrong site.
After the user logs in, the access key is no longer in the URL, so I can't do matches against it.
I'd like for the user to see the following URL:
http://mysite1.com/Login/12345
http://mysite1.com/Products/
http://mysite1.com/Admin/
While in reality they're on a different server:
http://mysite2.com/Products/
http://mysite2.com/Admin/
I have to emphasize that I really do need the URL to stay 'mysite1' for the user, when in reality they'll be on 'mysite2'. Please let me know if this is possible or not, or if there's a better solution for it.
Sorry if this is a confusing scenario or if there's some information that I'm missing. I'll make edits if necessary.
Virtually anything is possible, but this approach seems really painful.
IIS can perform URL rewriting but it's going to be doing this before it hits the authentication layer so it will not be possible to differentiate users at that level.
It seems like the best option will be to write a custom URL rewriter provider. Looks like this post is attempting to solve it that way.
It really seems better to either redirect to a different server (which I know you're saying you can't do) or merge the multiple versions of functionality into a single app (with different controls/backend models, etc.)
This link may help in understanding a little bit about how the flow works in an ASP.NET MVC app.
I am working with an MVC 4 app running on IIS 7.5. I want to create a rewrite rule but I am not familiar with it so assistance is required.
The following URL will called by my application
/image/[language]/category/[id]-[size]-[priority]_Some+Random+Text.[extension]
I want to rewrite this in to the following as this is where the file will exist on disk.
/image/[language]/category/product/pr_[id]_[size]_[priority].[extension]
Any ideas of the rule I could use to achieve this?
URL Rewrite in IIS will accept RegEx rules. I believe the following rule would be appropriate here (YMMV, I can't test it at the moment - you can test it yourself using the 'Test Pattern' button available when editing a rewrite rule in the IIS Manager.
^image/[a-zA-Z]+/category/[a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+[_a-zA-Z\+]\.[a-zA-Z0-9]{,3}
and the rewrite action
images/{R:1}/category/producer/pr_{R:2}_{R:3}_{R:4}.{R:5}
This may be more general than you need (IDs might only be (hexa)decimal, size might only be decimal, etc.) but should give you the general gist of how it should be written.
This reference should provide any other information you need and the syntax for writing the rules directly into a web.config.
I have implemented URL rewriting using Intelligencia, everything works perfectly.
now if i have an anchor i could do somenthig like
Test
with the seo friendly url olready in place
or do i have to do somenthing like
Test
public string GetSeoUrl(string url)
{
if(url == "../TestPage.aspx") return ../TestPage;
}
This will allow me to manage from a central location all the URLs.
I am working on .net 3.5 Web Form
But what are the implications of both approaches?Is it going to be slower?less efficient?is the right way to do it?
Thanks
I think second way is right way to do it. ( Managing from Central Location )
also,i don't think there will be any SEO implication using this as the final URL will be same but second one is rendred from server.
It might be littlebit slow but not noticable. as it runs some server code to generate url while first cenarion there won't be any processing.
I see you are using .NET, you can to do this already developed solution from ASP.NET MVC Framework called URL routing.
Read this http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx
I would do the first one. The URL is the contract. Using the second approach may make you think that you can easily change the URL by updating the function. Changing the URL would cause seo issues.
This is the scenario: I have a list of about 5000 URLs which have already been published to various customers. Now, all of these URLs' location has changed on my server side. The server is still the same though. This is a ASP.NET website with .NET3.5/C#.
My requirement is : Though the customers use the older source URL they should be redirected to the new URL without any perceived change or intermediate redirection message etc.
I am trying to make sense of the whole scenario:
Where would I put the actual mapping of Old URL to New URL -- in a database or some config. file or is there a better option?
How would I actual implement a redirect:
Should I write a method with Server.Transfer ot Response.Redirect?
And is there a best practice to it like - placing the actual re-routing in HTTPModules..or is it Application_BeginRequest?
I am looking to achieve with a best-practice compliant methodology and very low performance degradation, if any.
If your application already uses a database then I'd use that. Make the old URL the primary key and lookups should be very fast. I'd personally wrap the whole thing in .NET classes that abstracts it and allow you to create a Dictionary<string,string> of all the URLs which can be loaded into memory from the DB and cached. This will be even faster.
Definitely DON'T use Server.Transfer. Instead you should do a 301 Permanently Moved redirect. This will let search engines know to use the new URL. If you were using NET 4.0 you could use the HttpResponse.RedirectPermanent method. However, in earlier versions you have to set the headers yourself - but this is trivial.
Keep the data in a database, but load into ASP.NET cache to reduce access time.
You definitely want to use HTTPModules. It's the accepted practice, and having recently tried to do it inside Global.asax, I can tell you that unless you want to do only the simplest kind of stuff (i.e. "~/mypage.aspx/3" <-> "~/mypage.aspx?param1=3) it's much more complicated and buggy than it seems.
In fact, I regret even trying to roll my own URL rewriting solution. It's just not worth it if you want something you can depend on. Scott Guthrie has a very good blog post on the subject, and he recommends UrlRewriter.net or UrlRewriting.net as a couple of free, open-source URL rewriting solutions.
Good luck.
I'm probably going to use the URL rewrite module for IIS 7 eventually and I have a fairly straight forward question that I really can't find the answer to.
If you have a base case of:
http://yoururl.com/page.aspx?ID=7
You can obviously have it rewritten to:
http://yoururl.com/page/7 or whatever you want.
My question is this: When using this module can you still use Request.Querystring["page"] on the rewritten querystring. How does the Request.URL stuff work. Does asp.net still provide the un-rewritten url or does it provide the rewritten one.
I would assume that your C#/asp.net code is completely unaffected by the url rewriting, as that's more or less the point, but I want to be crystal clear.
Secondary question: What is the best practice for how you should code a website when using the rewritten. Should you code links in the written style, or continue using querystrings?
When using this module can you still use Request.Querystring["page"] on the rewritten querystring.
Yes, you will be able to access the re-written QueryString in that way.
How does the Request.URL stuff work. Does asp.net still provide the un-rewritten url or does it provide the rewritten one.
Request.Url will be the re-written URL, but Request.RawUrl will be the original URL.
Should you code links in the written style, or continue using querystrings?
Yes, code your links in the way you want them to be seen by end users, and then in your code ensure you're aware of and document the changed format.
There is loads of information and tutorials on the IIS website here:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/