RequestContext Via Property has Machine Name instead of URL in IIS - c#

I am doing some work with OAuth and need to get the URL of the request. To do this I am doing the following:
operationContext.RequestContext.RequestMessage.Properties.Via
This was working great in Visual Studio Development Server because it would return
http://localhost:12345/{myrequest}
However, when pushed to IIS, and setting my project properties to use Custom Web Server with a value of this:
http://www.mydomain.com/
This is now showing a URL like the following in my RequestContext:
http://{machinename}/{myrequest}
Instead of:
http://www.mydomain.com/{myrequest}
Is this an IIS setting? To get around this, I am forced to modify the URI instance to swap out the machine name with the domain name. This is non-ideal.
Anything I am missing here?

Related

How do I setup reverse proxy in local IIS

I have to implement reverse proxy setup in my local system. I have two website and in first website i have content and second website have empty forlder, I have one website example - www.nawaz-data.com and it has main content. and I have another website example - www.nawaz-proxy.com which is empty folder .
Requirement :
Need how do i setup for reverse proxy. When i request to www.nawaz-proxy.com than it should be redirect to www.nawaz-data.com where i have actual website content. I have tried to setup inbound and outbound rule but unable to get result it shows : HTTP Error 403.14 - Forbidden as this domain has no content, i want to redirect this url to another url where content has stored.
I have installed IIS windows 10
I have installed URL Rewrite
I have installed Application Request Routing Cache - in that I have enable proxy setting
According to your description, I suggest you could try to use below steps to add the reverse proxy rules.
1.Open the IIS mangement console, locate the right web site and click the url rewrite
2.Click the Add rule and select reverse proxy.
3.Add the servername op IP in below window, for example: www.nawaz-data.com. Notice: you should make sure your server could access the "www.nawaz-data.com" directly by using brower. If you couldn't access it ,you should use server's ip address directly.

ASP .Net MVC 5 redirect issue

Currently I have an internal server serv that has an application app.
It is running MVC 5 and has 2 pages Account/Logon which maps to controller and an action.
And Orders/Display (again controller/action)
In order for internet users in the outside world to see I have a host server host running IIS. It maps host URLs to the internal app like so
host/Account/Logon -->serv/app/Account/Logon
So basically anything after host/... gets changed to serv/app/....
My problem is if I do RedirectToAction("Display","Orders");
(there are lots of these redirects because there's lots of controller/action combos.
The internal server grabs the host portion but also tacks on "app" in order
to switch to the next page or route
So,host/app/Orders/Display
My problem is that the host IIS maps this URL to host/app/app/Orders/Display
because that what it's mapping is set to do. always add "app"
How can I solve this issue? Is there any way for serv do
a relative mapping? In order words it only sees the original host/Account/Logon
so on switch it would be host/Orders/Display?
Use Redirect() instead of RedirectToAction() and pass in the url.

SharePoint Sandbox Solution Failing based on Web Address used

I have a SharePoint 2010 Sandbox Solution working perfectly on my dev machine if I view the page as: http://dev/page.aspx it works great.
However, if I view the page as http://dev.corp.company.com/page.aspx I get the following error:
Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: File Not Found.
Error throws even when viewing a blank web part with no code behind.
[assembly: AllowPartiallyTrustedCallers()]
is present.
It looks like I need to configure alternate access mappings:
http://technet.microsoft.com/en-us/library/cc288609(office.12).aspx
Alternate access mappings have not been configured. Users or services
are accessing the site http://dev with the URL
http://dev.corp.company.com. This may cause incorrect links to be
stored or returned to users. If this is expected, add the URL
http://dev.corp.company.com as an AAM response URL. For more
information, see: http://go.microsoft.com/fwlink/?LinkId=114854"
ALSO:
The Web application at http://skynet.redmond.corp.microsoft.com/ could
not be found. Verify that you have typed the URL correctly. If the URL
should be serving existing content, the system administrator may need
to add a new request URL mapping to the intended application. at
Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean
contextSite, SPUserToken userToken) at
Microsoft.SharePoint.SPSite..ctor(String requestUrl) at
Microsoft.SharePoint.SPSite_SubsetProxy.SPSite__Factory(String
requestUrl)

How to retrieve on which site the web application is currently running?

I am currently running a WCF service on an AppFabric server and my application needs to load a the web.config file dynamically to retrieve custom configuration sections.
On my development machine I can just load the configuration like this:
WebConfigurationManager.OpenMappedWebConfiguration(webMappedFile, virtualPath);
But on the test machine (AppFabric server) I am getting an exception and it seems that I need to specify a third parameter which is actually the site the web application is running on:
WebConfigurationManager.OpenMappedWebConfiguration(webMappedFile, virtualPath, "MySite");
So I tried to hard code it and it worked. Anyway this is not acceptable, so I need to dynamically provide the site to the WebConfigurationManager because I do not on which site the service will be running in the future. Do anybody knows how to achieve that?
Thanks.
If you are running this code as part of handling a request you could use:
Request.ServerVariables("server_name")
see: http://msdn.microsoft.com/en-us/library/ms525396(VS.90).aspx
Edit based on your comment
The parameter that you need is the Site Name, not the machine name, your code be running on many machines. If the code is running somewhere where it no longer knows that it is on a web site, then it is difficult for it to get the name of the web site that it is running on.
You then have two options:
Send the name as a parameter from a layer that has httpconext
Not sure if this will work: but you could try adding a reference to system.web to your project. It may compile, but you could get a null reference exception when you run it. Probably worth a try.
How about Server.MachineName

SPItemEventReceiver Context SiteId/WebUrl Incorrect

I have created a SharePoint Event Receiver, that fires on Item Update.
The receiver needs access AfterProperties and ListItem.
When firing the event receiver from a SharePoint web application using an IP address (http://10.0.4.50/sites/), it throws a FileNotFoundException, when accessing SiteId And WebUrl in SPItemEventProperties.
The Web application at http://10.0.4.50/sites/companyName could not be found. Verify that you have typed the URL correctly.
When firing the event receiver using the hostname, specified at setup of Site Collection http://computerhostname/sites/companyName. This works fine, no exception is thrown.
//Combine Both AfterProperties And ListItem
var ListProperties = new List<KeyValuePair<string, object>>();
ListProperties.AddRange(properties.AfterProperties.ToKeyValue());
ListProperties.AddRange(properties.ListItem.ToKeyValue(p => !p.Sealed));
var AvaliableProperties = ListProperties.Distinct(new KeyValueComparer<object>());
This isn't necessarily a SharePoint problem, but is most likely down to the way that IIS is configured on the host. A particular site can be "bound" to an IP address and a host name, and if the host name isn't present in the HTTP GET sent by the browser then IIS will return a 404 NOT FOUND.
You can verify this by using a browser to see whether you can access the site by IP address.
You can add additional bindings if necessary, but there can only be one "default" binding per IP address, so only one site can be present at (in your case) 10.0.4.50.
A possible way around the situation where multiple sites are present but you can't use a hostname might be to add a binding to a port other than port 80 for this IP, so your URL would become something like http://10.0.4.50:8080/sites/companyName.
This is not just an IIS problem, but Sharepoint related as well. A lot of referencing in SharePoint is done by using a url as a starting point (just look at the constructor of SPSite). The url is then compared to known url's in SharePoint's Config database. (and ofr files etc in the site's content database).
SharePoint uses a system called Alternate Access Mappings to assign different urls to a Web Application's "Zones" (default, intranet, internet, ... custom definition). If it does not find the 'exact' Url, internally stuff will fail (And especially search is very "Url sensitive").
Then comes the IIS part into play: Since IIS probably has no other site running on the 80 port, and without a specific hostheader (so it defaults to machinename), or with the hostheader set to the machine name, IIS will pick up the request and since SharePoint is tied into this webapp, SharePoint will try to process it, looks up the url, Sharepoint does not find the Url and thne "breaks".
The no hostheader occurs when you leave the hostheader field empty when you create a new web app in SharePoint.

Categories

Resources