Issue with Response.TransmitFile - debugging

I have been working on an issue for the past 2 days.I have tried to debug in every way possible but in vain.
Everything works fine on my local.But on production this fails.
Here is a brief description about the problem.
I have a download button and when I click that button I intend to download a file from a server.
protected void Download_Click(object sender, EventArgs e)
{
Button downloadButton = sender as Button;
string filePath = downloadButton.CommandArgument;
string stuid = Session["browse_files_for_student"].ToString();
string stuUsername = MyHelper.GetUsernameForStudentID(stuid);
MyHelper.LogAccess(User.Identity.Name, StudentUsername.Text, filePath, MyHelper.LogAccessType.Read);
FileInfo file = new FileInfo(filePath);
// Download the file
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + file.Name);
try
{
Response.TransmitFile(filePath);
}
catch (IOException error)
{
Response.Cookies.Add(new HttpCookie("global_last_error", "The file is in use by another process."));
Response.Redirect("~/Public/KnownError.aspx");
}
Response.End();
}
I see on the Event Viewer that it generates:
TransmitFile failed:FileName:dsdfsfd.doc,Impersonation Enabled:0,Token Valid:1 HRESULT:0x8007052e.
Environment: The website is deployed on a Windows 2000 server.
Any help and comments would be appreciated.
Thank you.

The account under which your application is running (probably IIS pool account) does not have access to the file that you are trying to send. The error code 0x8007052e means:
Error code: (HRESULT) 0x8007052e (2147943726) - Logon failure: unknown user name or bad password.
In the future you can check the error code using for instance cdb command (cdb is a part of the freely available Windows Debugging Tools):
cdb notepad.exe
And then after it has started:
0:000> !error 0x8007052e
Error code: (HRESULT) 0x8007052e (2147943726) - Logon failure: unknown user name or bad password.
Hope it helps :)

Related

Open Uri to read JSON file in background task UWP

I have a use case where I have to read a config.json file from an AppService and based on the configuration in json file I have to generate an ID.
I am using following piece of code to generate the Uri so that I can open the file using StorageFile.GetFileFromApplicationUriAsync(fileUri).
Uri fileUri = null;
try
{
Debug.WriteLine("Creating new uri");
fileUri = new Uri(fileName);
if (fileUri == null)
{
Debug.WriteLine("Uri creation failed");
} else
{
Debug.WriteLine("New Uri created");
}
} catch (Exception ex)
{
Debug.WriteLine("Uri creation failed" + ex.Message);
}
Now when I am trying to debug this code my debugger is disappearing after line with new Uri(fileName)
If I just let the code run with no breakpoints I am not seeing any message after Creating new uri. Not even an exception.
Value of fileName is "ms-appx:///config/config.json"
Can anyone please explain what is wrong here? Also is it possible to open and read a file from an AppService?
--
Thanks
Tarun
The uri use appx only can read the resource is content in msbuild.
You can right click the file and select the property and you should select the file's build action as content.
http://jycloud.9uads.com/web/GetObject.aspx?filekey=449e34647d61faca2ce846b773a4da8e
http://jycloud.9uads.com/web/GetObject.aspx?filekey=5423b79037eee8dc66431d0478d79871
http://jycloud.9uads.com/web/GetObject.aspx?filekey=6189eb9547c6f2fa79333df67ab33cef
You can see the last image is use complie and you can change it to content.
Sorry, my visual studio's language is local language.But the visual studio's have the same layout.

The given key was not found in the dictionary

I'm developing windows phone 8 application. In this, I have to integrate Twitter. So I have followed the below tutorial.
http://code.msdn.microsoft.com/wpapps/Latest-Twitter-integration-a42e8bb6
I've implemented successfully twitter in my application. I've tested this in Emulator and in device also. Everything was fine.
**Suddenly in the device the application is unable to open the twitter log in page. I'm getting the error in the below method at line started with .
void requestTokenQuery_QueryResponse(object sender, WebQueryResponseEventArgs e)
{
try
{
StreamReader reader = new StreamReader(e.Response);
string strResponse = reader.ReadToEnd();
var parameters = MainUtil.GetQueryParameters(strResponse);
**OAuthTokenKey = parameters["oauth_token"];**
tokenSecret = parameters["oauth_token_secret"];
var authorizeUrl = AppSettings.AuthorizeUri + "?oauth_token=" + OAuthTokenKey;
Dispatcher.BeginInvoke(() =>
{
this.loginBrowserControl.Navigate(new Uri(authorizeUrl, UriKind.RelativeOrAbsolute));
});
}
catch (Exception ex)
{
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(ex.Message);
pi.IsVisible = false;
});
}
}
The given key was not present in the dictionary.
But in Emulator I'm successfully redirected to log in page if user is not logged in and posting the message.
I don't know what is the problem in the device.
This issue occurs when the the device you are using for testing the app is without simcard, as it the device without the simcard cannot match the timings of the twitter api server and this mismatch causes the authentication error, as for the api the credentials are invalid due to heavy difference in the timings between api server and device, hence try checking it on a device that has a simcard inside.

Acessing ReportService in ReportServer From Windows Application

Here i have a windowsapplication and a SSRS Report where report is implemented in Report server,and herei try to call that report from a windows application.In my button click i add this code:
string reportName = "Crime_Traking_Report";
reportViewer1.ServerReport.ReportServerCredentials =new ReportServerCredentials("isroScientist", "password12345678", "Nasa");
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
try
{
reportViewer1.ServerReport.ReportServerUrl = new Uri("http://13.88.91.156/ReportServer");
}
catch (UriFormatException)
{
Console.WriteLine("Bad Url format");
}
reportViewer1.ServerReport.ReportPath = "/iSROReportsStandard/" + reportName;
reportViewer1.ProcessingMode = ProcessingMode.Remote;
reportViewer1.ServerReport.Refresh();
Here definitely i want to pass the credentials to access ,but when i run my application its giving an error like this "ReportServerCredentials has no constructor Defined", what change i want to make in order to pass the credentials successfully through my code.please explain me through code.
The question is has the same solution as your other qustion Error while accessing report service(remote mode) from Report server with in a windows application. See my answer there. The ServerReport.SetDataSourceCredentials Method should be used.

WATIN-Run script Problem in IIS

I am using watin framwork. I have wrote code ie.Runscript('newnote()'); Its running in my pc IIS success. This code also runnign with client visual studio 2008 with success but failed with client IIS. I have also set all rights in IIS and web folder. also check with IE7 and IE8. We have verfied with SSL certificate.But we can not identify where is problem.
please, help me.
Error: (1) Run script failed. and some time (2)Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Code Like:
string mfnQS='45SDS82'
string noteURL = string.Format ("https://sitename.co.uk/apps/shared/dlg_addnoteform.jsp?{0}&parent_package=cxa&cid=", mfnQS);
ie.GoTo(noteURL);
ie.WaitForComplete(2000);
Thread.Sleep(2000);
objBO.NoteDetails = objBO.NoteDetails;
string sNote = StringUtility.RemoveHtmlTag(objBO.NoteDetails);
TextField notetext = ie.TextField(Find.ById("notetext"));
notetext.WaitUntilExists(2000);
notetext.Value = sNote;
notetext.WaitForComplete();
ie.RunScript("$('iframe').contents().find('html body').html(document.addnote.notetext.value)");
WatiN.Core.Button btnAdd = ie.Button(Find.ByValue("ADD NOTE"));
if (btnAdd.Exists)
{
if (ClsReadOnlyKeyword.IsFinalVersion)
{
ie.RunScript("newnote();");
Thread.Sleep(2000);
isTrue = true;
}
}

Windows Azure: Error 300 Ambiguous Redirect when creating a blob container

I followed a tutorial on creating a blob on windows azure. But when I do that, I get an exception error:
Error while creating containerThe server encountered an unknown failure: The remote server returned an error: (300) Ambiguous Redirect.
The code is:
private void SetContainersAndPermission()
{
try
{
// create a container
var CloudAccountStorage = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");
cloudBlobClient = CloudAccountStorage.CreateCloudBlobClient();
CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents");
blobContainer.CreateIfNotExist();
// permissions
var containerPermissions = blobContainer.GetPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Container;
blobContainer.SetPermissions(containerPermissions);
}
catch(Exception ex)
{
throw new Exception("Error while creating container" + ex.Message);
}
}
Can anyone tell me How to solve this problem....
I would guess the connection string is somehow wrong? Can you share the connection string? (X out your shared key...)
You could also install Fiddler (debugging HTTP proxy) and see what the HTTP request looks like. That may make the issue more obvious.
I also faced the same issue. I am not sure if this is the workaround for it. I modified the container name value in ServiceConfiguration.csfg from "Photograph" to "photograph" and it worked.
I think you can not give upper case letters in queue, table or blob name. The name should have only lower case characters.

Resources