Currently I have an ASP.net 4.0 app in which I've made a web reference to an MOSS 2007 server. When I access any lists.asmx methods from the root application, everything works fine. However, if I try to change the service URL in C# code-behind to that of a subfolders list.asmx, then access the any method, I get a 404 error. The really strange thing though is if I take the URL that I've changed it to and plug it manually into IE and run it, the service loads fine (giving me a list of any methods available as expected.)
Here's a rundown of my code that I'm using:
This works:
ListsService.Lists m_listService =
ICredentials m_credentials = CredentialCache.DefaultCredentials;
m_listService.Credentials = m_credentials;
// No change to URL, defaults to 'http://mosstest/SiteDirectory/RootApp/SubApp/_vti_bin/lists.asmx'
XmlNode listColl = m_listService.GetListCollection(); // Works fine, gives me collection of lists in the root folder.
This doesn't work:
ListsService.Lists m_listService =
ICredentials m_credentials = CredentialCache.DefaultCredentials;
m_listService.Credentials = m_credentials;
m_listService.Url = "http://mosstest/SiteDirectory/RootApp/SubApp/Subfolder1/_vti_bin/lists.asmx";
XmlNode listColl = m_listService.GetListCollection(); // Throws a 404 Not found error.
Anyone else run into something similar?
Turns out I was trying to access a List itself, which in turn was not an application. I'm learning this headfirst. I will note however that SP seems to not give a 404 error when accessing via the browser, regardless of the URL. If I type in something like "http://mosstest/SiteDirectory/RootApp/SubApp/Subfolder1/_vti_bin/lists.asmx", with SubFolder1 not existing, it still gives a list of methods "available" and runs as if a service was indeed there. Not sure why it does this, but it does cause a great deal of confusion.
Related
I'm trying to configure HTTPS for my application and it's returning "HTTP Error 404. The requested resource is not found.", but the resource actually exists.
I've done several tests regarding this problem and here's a list:
Access via HTTP works perfectly.
I created a simple HTML file to try to access via HTTPS (https://example.com/myfile.html) and it also worked (which leads to the understanding that the problem is in something in my application).
Setting binding security mode to "Transport" in WebConfig file.
Port 443 for HTTPS is fine
PS.: When I try to access the site by HTTPS, by a route and resource that REALLY exists (for example "https://example.com/login.aspx") it returns 404 and recognizes the site as not secure (or i.e. it doesn't recognize the certificate in the route, maybe because it redirects me to http). But, if I try to access a resource that DOES NOT exist, like "https://example.com/Testlogin.aspx", it returns 404 but with a different message (comparisons attached) and recognizes the site as secure (HTTPS).
It's a C# webforms application with aspx, and I'm trying to set it up on IIS server.
Solved!
After many tests and running out of alternatives, I decided to investigate whether there was something in the source code that prevented the application from accessing HTTPS. Behold, I finally found the problem: in the application there was the following method that was redirecting the application to HTTP. I just needed to change the call parameter to true and it worked.
public void protocoloSeguro(bool bSeguro)
{
string redirectUrl = null;
if (bSeguro && !Request.IsSecureConnection) redirectUrl = Request.Url.ToString().Replace("http:", "https:");
else
if (!bSeguro && Request.IsSecureConnection) redirectUrl = Request.Url.ToString().Replace("https:", "http:");
if (redirectUrl != null)
Response.Redirect(redirectUrl);
}
I am trying to create Lists in Sharepoint site from my ASP.NET code using the webservice (http://test.sharepoint.com/_vti_bin/Lists.asmx).The code i use is as follows.I am sure i have enough access to that sharepoint site.
sharepoint.enhanced1.Lists wsLists = new SharePoint_Test.sharepoint.enhanced1.Lists();
wsLists.PreAuthenticate = true;
wsLists.Credentials = System.Net.CredentialCache.DefaultCredentials;
wsLists.AddList("Test_Code", "testing", 103);
This Code gives me the error:-
The request failed with HTTP status 401: Unauthorized.
Can anyone help me with this.
It's Working now..
i was using somewhat wrong asmx URL.
the one i was using was http://test.sharepoint.com/Lists/_vti_bin/Lists.asmx
but the correct URL Shud be
http://test.sharepoint.com/_vti_bin/Lists.asmx (**NO /Lists/).
Strange thing is that both URL's open up in browser without any problem,but fail in code.
Thanks...
try it with the default network credentials
wsLists.Credentials = System.Net.CredentialCache.DefaultCredentials;
I have the same error and finaly disable ASP.NET Impersonation for my Sharepoint site in IIS Manager.
I have a HttpModule which intercepts all requests and loads data from the database based on routing rules. However, I run into one problem all the time; GetRouteData only works if the path does not exist:
var routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
Assuming a request comes in for the url http://localhost/contact, I get the correct routing data relating to that url if that path does not exist in the file system. The problem appears when I want to customize the page at that url which I do by creating an aspx page in the path ~/contact/default.aspx. Once I do that, GetRouteData return null.
I have even tried creating a new HttpContext object, but I still can not retrieve route data if the page exists.
Has anyone ever run into this problem? Is there a solution/workaround?
All help will be greatly appreciated.
Set RouteCollection.RouteExistingFiles to true.
public static void RegisterRoutes(RouteCollection routes)
{
// Cause paths to be routed even if they exists physically
routes.RouteExistingFiles = true;
// Map routes
routes.MapPageRoute("...", "...", "...");
}
Beware though. IIS7 behaves a little differently than the server used when debugging within Visual Studio. I got bit by this when I deployed my application to the web. Check out this feedback I submitted to Microsoft Connection.
Let's say that I have my ASP.NET web application in a directory called "MyApp" both locally and on a remote server. I'm trying to build an onclick response to a link. The response calls a Javascript function, passing it the URL of an .aspx page in my web app. The Javascript pops out a new window displaying the page. My C# code looks like this:
link = new HyperLink();
link.Text = product_num_str;
link.NavigateUrl = "#";
string url = "Javascript:My_NewWindow('http://" +
HttpContext.Current.Request.Url.Authority +
"/ProductInfo.aspx?_num=" + product_num_str + "')";
link.Attributes.Add("onclick", url);
I started using the Request's Authority property because I was having problems running locally on the Visual Studio web server when I used the Host property. The problem was that Host only returned "localhost" instead of the host and port number.
When tested locally, the code works because the "authority" maps to my app root folder. The URL generated is, e.g.,
http://localhost:52071/ProductInfo.aspx?_num=123
If I run on a remote server, however, I end up with something like:
http://company-server/ProductInfo.aspx?_num=123
This fails to find the page, because in this case the "MyApp" root folder must be included.
There is probably an easier way - putting an entry in the web.config or something. My motivation originally was to allow the app to be published to a folder of any name and work as is.
I could hack my approach and search the string for "localhost" or something, but that's ugly. So how do I build a string that will work everywhere?
I'm assuming you're doing this from within a Page or Control. If that's the case you should do this instead:
string fullUrl = this.ResolveClientUrl("~/ProductInfo.aspx?_num=" + product_num_str + ");
That will give you the proper URL no matter where the application is deployed.
I've got an ASP .Net application running on IIS7. I'm using the current url that the site is running under to set some static properties on a class in my application. To do this, I'm getting the domain name using this (insde the class's static constructor):
var host = HttpContext.Current.Request.Url.Host;
And it works fine on my dev machine (windows XP / Cassini). However, when I deploy to IIS7, I get an exception: "Request is not available in this context".
I'm guessing this is because I'm using this code in the static constructor of an object, which is getting executed in IIS before any requests come in; and Cassini doesn't trigger the static constructor until a request happens. Now, I didn't originally like the idea of pulling the domain name from the Request for this very reason, but it was the only place I found it =)
So, does anyone know of another place that I can get the host domain name? I'm assuming that ASP .Net has got to be aware of it at some level independent of HttpRequests, I just don't know how to access it.
The reason that the domain is in the request is...that's what's being asked for. For example these are a few stackexchange sites from http://www.stackexchangesites.com/:
http://community.ecoanswers.com
http://www.appqanda.com
http://www.irosetta.com/
If you ping them, you'll see they all point to the same IP/Web Server and be served by the same app (or multiple apps in this case, but the example holds if it was one big one)...but the application doesn't know which one until a host header comes in with the request asking the server for that site. Each request may be to a different domain...so the application doesn't know it.
If however it doesn't change, you could store it as an appSetting in the web.config.
Use global.asax or write a HttpModule and subscribe to start request events. You will have the request passed into your event handler.
Use this instead:
HttpRuntime.AppDomainAppVirtualPath
Or if you want the physical path:
HttpRuntime.AppDomainAppPath
For further reading:
http://weblogs.asp.net/reganschroder/archive/2008/07/25/iis7-integrated-mode-request-is-not-available-in-this-context-exception-in-application-start.aspx