Found uknown characters and special characters in url in ap.net C# - c#

I am getting some special characters and some letters along with the url at runtime. The url is like
http://b1.elenageosystems.com/%28S%28z1qmpcpllhmuoxgsnkhcbflh%29%29/Default.aspx
Here you can see the special characters appended along with the url after b1.elenageosystems.com/.....
Default.aspx is my page
You can view my project - www.b1.elenageosystems.com

This is so-called Session ID that used by IIS to manage your sessions, it is added to every URL firing from the same browser session.
Many IIS-based frameworks (for example classical ASP.NET) depend heavily on sessions and require this ID to overcome generale stateless nature of HTTP requests, this is why IIS provides (and implements) fully transparent support for it.
If you don't like these URLs, you can also use Cookies to store your Session ID. You can configure the way how you store your IDs for sessions either per WebApplication using your web.config file in your application or globally for your complete IIS server.
You find more how to change these settings on MSDN.

Related

Making relative urls in asp.net webform custom classes without Request

I have some kind of a job scheduling implemented which calls a function ProcessJob. Now inside this method I need to generate url to one of my pages i.e DoanloadPage.aspx?some_params. That url is sent to user via email and when user clicks that link, it will take to the page.
The problem here is that I am not generating url in a web request method or I don't have access to the Request object. URL need to be generated in a custom class which is threaded i.e not in a web request.
So I can't go with these solutions:
HostingEnvironment.MapPath("test.aspx");
VirtualPathUtility.ToAbsolute("123.aspx");
HttpContext.Current.Request.Url.Authority;
None of these works because I think they all rely on current request or session somehow. So how do I generate urls for my app inside my code so I can use them anyway I want.
If your method cannot use HttpContext.Current.Request.Url, for example in case it's a background scheduled task, then you can use either of the following options:
In case that your code is hosted in the same ASP.NET application, you can pass the site domain name of the site to your class, in the first request. To do so, you need to handle Application_BeginRequest event and get the domain from HttpContext.Current.Request.Url and then pass it to your class, or store it in an application scope storage. You can find an implementation in this post or the original article.
Note: The code is available in SO, so I don't repeat the code
here.
If your code is not hosted in the same ASP.NET application or if for any reason you don't want to rely on Application_BeginRequest, as another option you can store the site domain name in a setting (like appsettigs in app.condig or web.config if it's web app) and use it in your code.
You can do something like this. Dns.GetHostName will return the name of the computer that is hosting the site. You can use that to check if the site is on a development server.
string domain = "www.productionurl/123.aspx";
if (Dns.GetHostName() == "Development")
{
domain = "www.developmenturl/123.aspx";
}
The Dns.GetHostName() is not the only way to check. You could also use the HostingEnvironment.ApplicationPhysicalPath. You can check that also and see if the path is that of the development server.
My answer is: don't do this. You're building a distributed system, albeit a simple one, and generally speaking it is problematic to introduce coupling between services in a distributed system. So even though it is possible to seed your domain using Application_BeginRequest, you are then tying the behavior of your batch job to your web site. With this arrangement you risk propagating errors and you make deployment of your system more complicated.
A better way to look at this problem is to realize that the core desire is to synchronize the binding of your production site with the URL that is used in your batch job. In many cases an entry in the app.config of your batch would be the best solution, there really isn't any need to introduce code unless you know that your URL will be changing frequently or you will need to scale to many different arbitrary URLs. If you have a need to support changing the URL programmatically, I recommend you look at setting up a distributed configuration system like Consul and read the current URLs from your deployment system for both the IIS binding and the app.config file for your batch. So even in this advanced scenario, there's no direct interaction between your batch and your web site.

ASP.NET Unique Browser ID

I have a single solution with multiple C# ASP.NET Web Forms projects. I want a way to identify a given browser so that each website can identifier that same browser. I need to do this from the C# Code-Behind code (not with the client code, like JavaScript). I also cannot use the Session because it isn't shared across websites. I don't think cookies are either.
For example, if a user logs onto Website1 and then logs onto Website2 with the same browser on the same computer, I want to be able to identify that. But if a user logs onto Website1 with Chrome and then Website1 with FireFox (regardless of whether it's on the same computer or not), I want to detect that as well.
If it makes any difference, I am using Azure to publish my web projects. So all websites will have similar domains (eg website1.azurewebsites.net and website2.azurewebsites.net).
If you want to track someone using the same browser on the same computer then use a cookie. If the websites have different domains you'll need to be clever because modern browsers have a lot of protection against what they see as tracking cookies. One option is using a hidden interstitial page as described here.
Your second scenario, a user accessing same site with different browsers, I suggest storing the user agent string (one of the request headers) and adding this to a login audit so you can build up a collection of different user agents used by a given user. There are libraries available for parsing user agent strings and extracting name, version, engine etc.
Between these two techniques and a bit of business logic you should get what you need. If you would like me to clarify any of this, let me know and I'll provide more detail.

MVC Ensure User Travers Endpoints in Order

Say I have three endpoints
First/foo/bar
Second/fizz/buzz
Third/whatever
Only one of these endpoints is valid at a time, starting with first, then second, and so on. This is a problem is the user tries to go back, or they pick one of these endpoints from their history -- they'll be presented with an error dialog.
I thought I could use SessionState to keep track of the most recently accessed (and thus valid) endpoint and redirect with action filters based on that information, but my team has disabled SessionState.
So does MVC have a canonical way to ensure a user navigates certain endpoints in order?
MVC doesn't provide any behavior over what a browser does. That is, it is using the HTTP protocol and there is no way to prevent a user from manually typing in a URL in their browser (unless you have written your own browser that does this).
However, you could design your application as a single page that uses a JavaScript framework (such as JQuery or AngularJS) so the browser doesn't actually change URLs. This would prevent the browser from tracking the interaction between the JavaScript code and the server. Then you can guarantee that the user can only view the "pages" in the correct order.

Change ASP.NET MVC site language based on url referrer

I think I found a way (described below) to implement the following requested scenario, but I'll describe the complete context, in case I missed a simpler and/or cleaner solution to this issue.
The context
I have a multi-culture site that uses the following: ASP.NET MVC 5, EF 6.1, ASP.NET Identity 2.2, SimpleInjector. It is hosted on Amazon EC2 with sql server on Amazon RDS, while the urls are registered with www.register.it. I implement external OAuth login through FB, Linkedin, Google and Paypal payments.
I need to have multiple url (www.url-en.com, www.url-it.com etc) all pointing to the same site and then change language and _layout (masterpage) according to the url typed by the user.
The solution
Initially I thought about pointing all the urls to the ip of my site, but in this way I would need multiple ssl certificates configured (I don't even know if it's possible) and, more important, I wouldn't be able to manage callbacks from esternal login services and paypal payments.
So I configured redirection at the registrar level for each url to point to the main url (the english one), so I could read the HTTP_REFERRER variable in the global.asax Application_Start and set the culture cookie according to the referrer url.
I've an ActionMethod in the Home controller that set the culture cookie (the same used also by the language selector on the site's pages) and then I have a custom RazorViewEngine that picks the localized view (if present).
The issue is that, having the app_pool in integrated mode, I can't read Request object in Application_Start, so I tried to do it inside the OWIN Configuration method, but HttpContext.Current.Request.UrlReferrer is null. Should I get the referrer from the OWIN context? How could I do that?
It'd be better/simpler to do that in javascript checking whether url and referrer are different?
Thanks
Matteo
Why not detect the culture from the browser rather than using individual urls? Then based on the browser culture, you could tailor your urls to specific languages.
This would solve your multiple ssl issue, since you would only need one for the primary domain. It would also fix callback urls for payment gateways.
http://www.url.com/en-us/
http://www.url.com/es-es/

how to handle http requests from a browser using c#

I have a windows application developed in c#.Net which is used as a website blocker for a network.I have done this by modifying the hosts file.It works fine when urls are blocked like "www.yahoo.com".Now my requirement is I have to block the urls based on the keywords.i.e when the user just types "yahoo" in the browser,I should verify the keyword and block a corresponding website.Now how can I track the website typed by the user in the browser and block or allow the user to particular site based on the url.I should not allow the user to view the page if the keyword is present.How to do this?Can some one help me to do this?
There's plenty of code samples out there that will act as proxies (eg. http://code.cheesydesign.com/?p=393) however I would strongly suggest following the advice of the comments you've been given and go with an existing application.
Building a proxy that will not interfere with the complicated web apps of today is not trivial. You also need to be careful about blocking based on keywords - web apps I've worked on have failed in spectacular ways due to proxies doing this, and rejecting requests for important javascript files (often due to minification or compression) rendering our app useless.
Also consider that your proxy won't be able to check SSL traffic (which is increasing all the time) without serving up your own certs acting as a man-in-the-middle.

Categories