本文将分享c#–Xamarin:Android:System.UnauthorizedAccessException:拒绝访问路径的详细内容,并且还将对编程拒绝访问进行详尽解释,此外,我们还将为大家带
本文将分享c# – Xamarin:Android:System.UnauthorizedAccessException:拒绝访问路径的详细内容,并且还将对编程拒绝访问进行详尽解释,此外,我们还将为大家带来关于android – Linkedin:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:null、android – 使用Samba / JCIFS问题写入/上传文件(SmbAuthException:拒绝访问)、ASP.NET IIS System.UnauthorizedAccessException: 对路径“C:\.....”的访问被拒绝。(转)、asp.net-mvc – 在MVC 4应用程序中处理带有自定义错误的UnauthorizedAccessException的相关知识,希望对你有所帮助。
本文目录一览:- c# – Xamarin:Android:System.UnauthorizedAccessException:拒绝访问路径(编程拒绝访问)
- android – Linkedin:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:null
- android – 使用Samba / JCIFS问题写入/上传文件(SmbAuthException:拒绝访问)
- ASP.NET IIS System.UnauthorizedAccessException: 对路径“C:\.....”的访问被拒绝。(转)
- asp.net-mvc – 在MVC 4应用程序中处理带有自定义错误的UnauthorizedAccessException
c# – Xamarin:Android:System.UnauthorizedAccessException:拒绝访问路径(编程拒绝访问)
所以我正在尝试创建一个文件而我正在获取
System.UnauthorizedAccessException:拒绝访问路径“/ DownloadJitters”.我不确定它是否是权限(我已经尝试过写入外部存储,但是没有用)或其他东西.此外,我正在试图找出一个写这些文件的好地方,因为我希望它们不容易找到.有任何想法吗?这是代码:
public void favouriteList(MainActivity av, Ordering o, string favouriteName, string totalCost, JittersListView jlv)
{
//Checks Directory exists
if (File.Exists(Android.OS.Environment.DirectoryDownloads + "/Jitters/FavouritesListAdded.txt") == false)
{
Directory.CreateDirectory(Android.OS.Environment.DirectoryDownloads + "Jitters/FavouriteList/");
File.Create(Android.OS.Environment.DirectoryDownloads + "/Jitters/FavouritesListAdded.txt");
}
if (File.Exists(Android.OS.Environment.DirectoryDownloads + "Jitters/FavouriteList/" + favouriteName + ".txt") == false)
{
var fav = File.Create(Android.OS.Environment.DirectoryDownloads + "Jitters/FavouriteList/" + favouriteName + ".txt");
fav.Close();
string file = Android.OS.Environment.DirectoryDownloads + "Jitters/FavouriteList/" + favouriteName + ".txt";
string added = null;
int current = 0;
while (true)
{
if (current < jlv.Count)
{
JittersListItem jli = jlv[current];
added += jli.Top + "|" + jli.Bottom + "|" + jli.itemPic + "|" + jli.itemDes + System.Environment.NewLine;
current++;
}
else
{
break;
}
}
File.AppendAllText(file, favouriteName + "|" + totalCost + added);
}
else
{
new AlertDialog.Builder(av)
.SetMessage("Please use a different name, this one has been taken.")
.Show();
}
}
解决方法:
好的我通过将保存位置更改为来修复它
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)
不要问我为什么当他们需要相同的权限时才有效,但确实如此.
android – Linkedin:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:null
Config.java
public class Config { public static String LINKEDIN_CONSUMER_KEY = "75rbbjsc94argh"; public static String LINKEDIN_CONSUMER_SECRET = "G85WTKgcIijk4U6Yu"; public static String scopeParams = "rw_nus+r_basicprofile+r_fullprofile+r_emailaddress+r_network+r_contactinfo+rw_groups+rw_company_admin"; public static String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin"; public static String OAUTH_CALLBACK_HOST = "callback"; //public static String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST; public static String OAUTH_CALLBACK_URL = "x-oauthflow-linkedin://callback"; }
LinkedInSampleActivity.java
public class LinkedInSampleActivity extends Activity { Button login; Button share; EditText et; TextView name; ImageView photo; public static final String OAUTH_CALLBACK_HOST = "litestcalback"; final LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory .getInstance().createLinkedInOAuthService( Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET,Config.scopeParams); final LinkedInapiclientFactory factory = LinkedInapiclientFactory .newInstance(Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET); LinkedInRequestToken liToken; LinkedInapiclient client; LinkedInAccesstoken accesstoken = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); share = (Button) findViewById(R.id.share); name = (TextView) findViewById(R.id.name); et = (EditText) findViewById(R.id.et_share); login = (Button) findViewById(R.id.login); photo = (ImageView) findViewById(R.id.photo); login.setonClickListener(new OnClickListener() { @Override public void onClick(View v) { linkedInLogin(); } }); } private void linkedInLogin() { ProgressDialog progressDialog = new ProgressDialog( LinkedInSampleActivity.this); Linkedindialog d = new Linkedindialog(LinkedInSampleActivity.this,progressDialog); d.show(); // set call back listener to get oauth_verifier value d.setVerifierListener(new OnVerifyListener() { @Override public void onVerify(String verifier) { try { Log.i("LinkedinSample","verifier: " + verifier); accesstoken = Linkedindialog.oAuthService .getoAuthAccesstoken(Linkedindialog.liToken,verifier); Linkedindialog.factory.createLinkedInapiclient(accesstoken); client = factory.createLinkedInapiclient(accesstoken); client.postNetworkUpdate("Testing by Umesh!!! LinkedIn wall post from Android app"); Person p2 = client.getProfileForCurrentUser(EnumSet.of(ProfileField.ID)); Person p = client.getProfileById(p2.getId(),EnumSet.of( ProfileField.FirsT_NAME,ProfileField.LAST_NAME,ProfileField.SKILLS,ProfileField.HEADLINE,ProfileField.SUMMARY,ProfileField.LANGUAGES,ProfileField.LANGUAGES_LANGUAGE_NAME,ProfileField.LANGUAGES_PROFICIENCY_NAME,ProfileField.LANGUAGES_LANGUAGE,ProfileField.HOnorS,ProfileField.INTERESTS,ProfileField.POSITIONS,ProfileField.EDUCATIONS,ProfileField.INDUSTRY,ProfileField.API_STANDARD_PROFILE_REQUEST,ProfileField.PICTURE_URL,ProfileField.PUBLIC_PROFILE_URL)); name.setText("Welcome " + p.getFirstName() + " "+ p.getLastName()); Log.i("LinkedinSample","ln_access_token: " + accesstoken.getToken()); Log.i("LinkedinSample","ln_access_token: " + accesstoken.getTokenSecret()); Log.i("FirstName"," : " + p.getFirstName()); Log.i("LastName"," : " + p.getLastName()); Log.i("User Summary"," : " + p.getSummary()); Log.i("Headline"," : " + p.getHeadline()); Log.i("Interest"," : "+p.getInterests()); //---------------------------------------------------- for (Position position:p.getPositions().getPositionList()) { Log.i("position "," : " + position.getTitle()); Log.i("comp "," : " + position.getCompany().getName()); } for (Education education:p.getEducations().getEducationList()) { Log.i("Degree "," : "+ education.getDegree()); Log.i("School name "," : "+ education.getSchoolName()); } Log.i("Language "," : "); for(Language language:p.getLanguages().getLanguageList()) { Log.i(""," : "+language.getLanguage().getName()); } Log.i("Skill "," : "); for(Skill skill:p.getSkills().getSkillList()) { Log.i(""," : "+skill.getSkill().getName()); } Log.i("Honor"," : "+p.getHonors()); //---------------------------------------------------- name.setVisibility(0); login.setVisibility(4); share.setVisibility(0); et.setVisibility(0); } catch (Exception e) { Log.i("LinkedinSample","error to get verifier"); e.printstacktrace(); } } }); // set progress dialog progressDialog.setMessage("Loading..."); progressDialog.setCancelable(true); progressDialog.show(); } }
Linkedindialog.java
public class Linkedindialog extends Dialog { private ProgressDialog progressDialog = null; public static LinkedInapiclientFactory factory; public static LinkedInOAuthService oAuthService; public static LinkedInRequestToken liToken; //Construct a new LinkedIn dialog public Linkedindialog(Context context,ProgressDialog progressDialog) { super(context); this.progressDialog = progressDialog; } @Override protected void onCreate(Bundle savedInstanceState) { requestwindowFeature(Window.FEATURE_NO_TITLE);// must call before super. super.onCreate(savedInstanceState); setContentView(R.layout.ln_dialog); setWebView(); } // set webview. private void setWebView() { Linkedindialog.oAuthService = LinkedInOAuthServiceFactory.getInstance() .createLinkedInOAuthService(Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET); Linkedindialog.factory = LinkedInapiclientFactory.newInstance( Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET); Linkedindialog.liToken = Linkedindialog.oAuthService.getoAuthRequestToken(Config.OAUTH_CALLBACK_URL); WebView mWebView = (WebView) findViewById(R.id.webkitWebView1); mWebView.getSettings().setJavaScriptEnabled(true); Log.i("LinkedinSample",Linkedindialog.liToken.getAuthorizationUrl()); mWebView.loadUrl(Linkedindialog.liToken.getAuthorizationUrl()); mWebView.setWebViewClient(new HelloWebViewClient()); mWebView.setPictureListener(new PictureListener() { @Override public void onNewPicture(WebView view,Picture picture) { if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } } }); } //webview client for internal url loading class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view,String url) { if (url.contains(Config.OAUTH_CALLBACK_URL)) { Uri uri = Uri.parse(url); String verifier = uri.getQueryParameter("oauth_verifier"); cancel(); for (OnVerifyListener d : listeners) { // call listener method d.onVerify(verifier); } } else if (url.contains("https://www.linkedin.com/uas/oauth/redorangetechnologies.com")) { cancel(); } else { Log.i("LinkedinSample","url: " + url); view.loadUrl(url); } return true; } } /** * List of listener. */ private List<OnVerifyListener> listeners = new ArrayList<OnVerifyListener>(); /** * Register a callback to be invoked when authentication have finished. * * @param data * The callback that will run */ public void setVerifierListener(OnVerifyListener data) { listeners.add(data); } /** * Listener for oauth_verifier. */ interface OnVerifyListener { /** * invoked when authentication have finished. * * @param verifier * oauth_verifier code. */ public void onVerify(String verifier); } }
应用程序崩溃,单击登录按钮,错误显示在setWebView();在Linkedindialog类中.
以下是logcat:
01-17 15:50:06.513: E/AndroidRuntime(2544): FATAL EXCEPTION: main 01-17 15:50:06.513: E/AndroidRuntime(2544): com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider Failed: null 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getoAuthRequestToken(LinkedInOAuthServiceImpl.java:205) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.mukesh.linkedin.Linkedindialog.setWebView(Linkedindialog.java:65) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.mukesh.linkedin.Linkedindialog.onCreate(Linkedindialog.java:54) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.app.Dialog.dispatchOnCreate(Dialog.java:340) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.app.Dialog.show(Dialog.java:253) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.mukesh.linkedin.LinkedInSampleActivity.linkedInLogin(LinkedInSampleActivity.java:100) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.mukesh.linkedin.LinkedInSampleActivity.access$0(LinkedInSampleActivity.java:94) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.mukesh.linkedin.LinkedInSampleActivity$1.onClick(LinkedInSampleActivity.java:69) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.view.View.performClick(View.java:3480) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.view.View$PerformClick.run(View.java:13983) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.os.Handler.handleCallback(Handler.java:605) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.os.Handler.dispatchMessage(Handler.java:92) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.os.Looper.loop(Looper.java:137) 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.app.ActivityThread.main(ActivityThread.java:4340) 01-17 15:50:06.513: E/AndroidRuntime(2544): at java.lang.reflect.Method.invokeNative(Native Method) 01-17 15:50:06.513: E/AndroidRuntime(2544): at java.lang.reflect.Method.invoke(Method.java:511) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 01-17 15:50:06.513: E/AndroidRuntime(2544): at dalvik.system.NativeStart.main(Native Method) 01-17 15:50:06.513: E/AndroidRuntime(2544): Caused by: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider Failed: null 01-17 15:50:06.513: E/AndroidRuntime(2544): at oauth.signpost.AbstractOAuthProvider.retrievetoken(AbstractOAuthProvider.java:214) 01-17 15:50:06.513: E/AndroidRuntime(2544): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69) 01-17 15:50:06.513: E/AndroidRuntime(2544): at com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getoAuthRequestToken(LinkedInOAuthServiceImpl.java:196) 01-17 15:50:06.513: E/AndroidRuntime(2544): ... 18 more 01-17 15:50:06.513: E/AndroidRuntime(2544): Caused by: android.os.networkonmainthreadException 01-17 15:50:06.513: E/AndroidRuntime(2544): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084) 01-17 15:50:06.513: E/AndroidRuntime(2544): at java.net.InetAddress.lookupHostByName(InetAddress.java:391) 01-17 15:50:06.513: E/AndroidRuntime(2544): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242) 01-17 15:50:06.513: E/AndroidRuntime(2544): at java.net.InetAddress.getAllByName(InetAddress.java:220) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.httpconnection.<init>(httpconnection.java:71) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.httpconnection.<init>(httpconnection.java:50) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.httpconnection$Address.connect(httpconnection.java:351) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.httpconnectionPool.get(httpconnectionPool.java:86) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.httpconnection.connect(httpconnection.java:128) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80) 01-17 15:50:06.513: E/AndroidRuntime(2544): at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:164) 01-17 15:50:06.513: E/AndroidRuntime(2544): at oauth.signpost.basic.DefaultOAuthProvider.sendRequest(DefaultOAuthProvider.java:48) 01-17 15:50:06.513: E/AndroidRuntime(2544): at oauth.signpost.AbstractOAuthProvider.retrievetoken(AbstractOAuthProvider.java:177)
解决方法
if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }
这对我有用.希望它能为你效劳.
android – 使用Samba / JCIFS问题写入/上传文件(SmbAuthException:拒绝访问)
public boolean save2Samba(String text,String fileName) { try { // My Windows shares doesn't require any login/password // String name="login";//my windows username // String password="password1";//my windows password // sSambaFolder contains a path like MYPC/E/SharedFolderName/ String url = "smb://" + sSambaFolder.toLowerCase()+fileName; SmbFile file = null; try { // assume ANONYMOUS is my case but there is no description of this in JCIFS API NtlmPasswordAuthentication auth = NtlmPasswordAuthentication.ANONYMOUS; file = new SmbFile(url,auth); android.util.Log.i("TestApp",url); // output is like smb://mypc/e/sharedfoldername/file.txt; SmbFileOutputStream out = new SmbFileOutputStream(file); out.write(text.getBytes()); out.flush(); out.close(); } catch (Exception e) { e.printstacktrace(); return false; } return true; } catch (Exception e) { e.printstacktrace(); return false; } }
由于记录了网址,我确定它是正确的(我也使用上面提到的代码检查了网址并浏览了文件夹的内容).
但问题是我总是这样:
W/System.err(3214): jcifs.smb.SmbAuthException: Access is denied.
共享不受密码保护,因此我无需任何用户名/密码即可访问.我可以从另一个WinPC读取/写入/删除文件,不需要授权.此外,我尝试使用共享为WinPC上的用户创建密码,但结果是相同的.所以我尝试了几个版本的NtlmPasswordAuthentication没有运气:
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(""); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(":"); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("Administrator:"); //actual username on WinPC with shares NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("Administrator"); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,"Administrator",""); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,"","");
那么我做错了什么以及如何在没有auth时实现我的目标需要访问共享文件夹?BTW我的三星电视是基于Linux并使用samba客户端访问相同的共享文件夹没有问题并播放MP3从那里(嗯,是的,它只读).由于我的AOS设备通过WiFi(而不是通过以太网连接的电视)访问我的LAN,我还检查了使用笔记本电脑WiFi访问共享文件夹,发现没有问题.
添加:
我现在正在尝试执行以下行:
file = new SmbFile(url,auth); android.util.Log.i("save2Samba","file.exists(): " + file.exists());
并获得相同的访问被拒绝.我甚至都不想写文件……
解决方法
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,null,null);
该死的不是那么明显!
ASP.NET IIS System.UnauthorizedAccessException: 对路径“C:\.....”的访问被拒绝。(转)
解决方法:
一、在IIS中的默认应用程序池-->高级设置...-->标识改成Local System可以解决该问题。
二、在需要进行读写操作的目录下添加Network Service这个帐号。
具体过程:对该文件夹按右键--属性--安全--添加--高级--立即查找--在“搜索结果”下选“NETWORK SERVICE”--确定--确定--确定
三、在网上查询了很多信息,有下列几种解决方案:
1.可能是安装出了问题,重新安装 执行命令,aspnet_regiis -i ,记得要生启啊
2.提升everyone的权限到可修改
3.提升aspnet权限:控制面板-管理工具-计算机管理-本地用户和组 找到ASPNET 隶属于里面加上Administrators
4.将iis虚拟目录删掉后重新建
5.在web.config文件中加入<identity impersonate="true"/>
6. 若要授予 ASP.NET 对文件的写访问权,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。
everyone加写入权限
7.用xml文件保存系统选项设置,用asp.net写入,调试运行(ctrl+F5)正常。站点配置后运行报错:“对路径xxx.xml的访问被拒绝”。资源管理器->工具->文件夹选项->查看 不选"使用简单文件共享",右击xml文件,选"属性"点"安全"添加"aspnet",选"完全控制",即可。
asp.net-mvc – 在MVC 4应用程序中处理带有自定义错误的UnauthorizedAccessException
public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } }
然后我使用自定义错误(web.config)希望显示每个服务器错误的友好错误消息.
<customErrors mode="On" ></customErrors>
这似乎适用于大多数异常,我得到了预期的行为,因为正在显示自定义错误页面View(共享视图文件夹中的Error.cshtml).
但是我最近注意到,如果抛出的错误是UnauthorizedAccessException,这不是我看到的行为.
我有点难过,因为在fiddler中我看到这个UnauthorizedAccessException异常会返回一个普通的500内部服务器错误作为标准异常.
那么我的customError设置如何遵守标准异常,但是UnauthorizedAccessException却没有?
我怎样才能使它们表现相同,因为它们本质上都是一个我想阻止最终用户看到的错误.
解决方法
http://prideparrot.com/blog/archive/2012/5/exception_handling_in_asp_net_mvc
对于我的目的,使用HandleErrorAttribute和全局Application_OnStart处理错误似乎没什么意义,所以出于我的目的,我决定最好处理Application_OnSTart中的所有内容,
关于c# – Xamarin:Android:System.UnauthorizedAccessException:拒绝访问路径和编程拒绝访问的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于android – Linkedin:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:null、android – 使用Samba / JCIFS问题写入/上传文件(SmbAuthException:拒绝访问)、ASP.NET IIS System.UnauthorizedAccessException: 对路径“C:\.....”的访问被拒绝。(转)、asp.net-mvc – 在MVC 4应用程序中处理带有自定义错误的UnauthorizedAccessException的相关知识,请在本站寻找。
本文标签: