In the office project added below code in ribbon xml
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2010/07/customui" onLoad="Ribbon_Load">
<commands>
<command idMso="FileSaveAs" enabled="false" />
<command idMso="FileSave" enabled="false" />
</commands>
</customUI>
and also added below line of code in ThisAddIn.cs
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon1();
}
Could you please tell me how it is getting called when I open Word document using asp.net. Currently disabling of requested buttons not working.
Related
I finished coding my .NET MAUI application and everything was working fine in debug mode. All my data persistence needs were being met by Entity Framework Core for Xamarin, even though I am using it on .NET MAUI.
I have made the apk file and was testing it to see if everything was okay, but turns out the database is not being created. My application crashes once I attempt to do database operations. So I am not sure if it is incompatibility of EF Core with .NET MAUI (but it was working fine in debug) or there is something I missed.
I followed the tutorial accessed here https://learn.microsoft.com/en-us/ef/core/get-started/xamarin And below is my DataContext file
DataContext.cs
using Microsoft.EntityFrameworkCore;
using MedbaseRec.Models;
namespace MedbaseRec.Utils
{
public class DataContext : DbContext
{
public DbSet<QuestionPack> QuestionPacks { get; set; }
public DbSet<Question> Questions { get; set; }
public DataContext()
{
SQLitePCL.Batteries_V2.Init();
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "medbaseapplica.db3");
optionsBuilder.UseSqlite($"Filename={dbPath}");
}
}
}
The Android/iOS linkers are removing chunks of the Entity Framework Core / Sqlite assemblies due to the heavy use of reflection. You can instruct the linker to keep some of the important Entity Framework Core stuff like so:
Add an XML file named Linker.xml to your Android project.
Right click Linker.xml in your Solution Explorer then select Properties.
Change Build Action to LinkDescription.
Add the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<!-- Entity Framework Core -->
<assembly fullname="mscorlib">
<type fullname="System.String">
<method name="Compare"></method>
<method name="CompareTo"></method>
<method name="ToUpper"></method>
<method name="ToLower"></method>
</type>
</assembly>
<assembly fullname="System.Core" />
<assembly fullname="Microsoft.EntityFrameworkCore" />
<assembly fullname="Microsoft.EntityFrameworkCore.Sqlite" />
<assembly fullname="Microsoft.EntityFrameworkCore.Relational" />
<assembly fullname="SQLitePCLRaw.core" />
<assembly fullname="SQLitePCLRaw.batteries_v2" />
<assembly fullname="SQLitePCLRaw.lib.e_sqlite3.android" />
</linker>
The iOS linker is different and it removes some attributes Entity Framework depends on. You need to add an iOS-specific linker extension in that case:
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<!-- Entity Framework Core -->
<assembly fullname="mscorlib">
<type fullname="System.String">
<method name="Compare"></method>
<method name="CompareTo"></method>
<method name="ToUpper"></method>
<method name="ToLower"></method>
</type>
<type fullname="System.Reflection.AssemblyInformationalVersionAttribute" preserve="all" />
</assembly>
<assembly fullname="System.Core" />
<assembly fullname="Microsoft.EntityFrameworkCore" />
<assembly fullname="Microsoft.EntityFrameworkCore.Sqlite" />
<assembly fullname="Microsoft.EntityFrameworkCore.Relational" />
<assembly fullname="SQLitePCLRaw.core" />
<assembly fullname="SQLitePCLRaw.batteries_v2" />
<assembly fullname="SQLitePCLRaw.lib.e_sqlite3.ios" />
</linker>
This has been verified to work against Microsoft.EntityFrameworkCore.Sqlite version 5.0.17.
The LinkDescription XML files are documented here.
The problem was with the Linker that thought that my EntityFrameworkCore dependency is not needed. It was working a bit too well.
I switched it off in the csproj file as follows
<PropertyGroup>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
I do think however that I should have used <AndroidLinkSkip>Assembly1</AndroidLinkSkip> to make sure that the assembly would be skipped by the linker and included in the release build.
Here is a linker to the Xamarin linker page that relates to .NET MAUI too.
https://learn.microsoft.com/en-us/xamarin/android/deploy-test/linker
Can anyone post an example of how to setup fileuploaddialogbutton widget in a dialog?
I'm assuming this can be done - From the docs:
"The FileUploadDialogButton creates a button that opens a new dialog for uploading a file via the FileUploadField. Can be used inside edit dialogs where the upload must happen in a separate form in the new dialog."
The only results my searches seem to return is the Widget API documentation which offer no examples.
I've tried various random configurations in my dialog but get the JS error:
TypeError: c.setSize is not a function
c.setSize(cw || undefined, ch || undefined);
Note I'm not specifying any height or width in the config (documentation doesn't list them as options). Can anyone offer an example of how to configure this correctly (dialog.xml snippet would be great)?
Thanks in advance
EDIT:
Here is my dialog XML as it stands. It gives the error, but it's not the only version that causes this js error in the console, nor do I make any claims that this should work hence (due to the lack of documentation) me asking for an example.
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
height="{Long}700"
xtype="dialog">
<items
jcr:primaryType="cq:Widget"
xtype="tabpanel">
<items jcr:primaryType="cq:WidgetCollection">
<tab1
jcr:primaryType="cq:Panel"
title="Tab 1">
<items jcr:primaryType="cq:WidgetCollection">
<name
jcr:primaryType="cq:Widget"
fieldLabel="Enter name"
name="./theName"
xtype="textfield"/>
<description
jcr:primaryType="cq:Widget"
fieldLabel="Change description"
name="./changeDescription"
xtype="richtext"/>
<files
jcr:primaryType="cq:Widget"
collapsed="{Boolean}false"
collapsible="{Boolean}false"
title="Files"
xtype="dialogfieldset">
<items jcr:primaryType="cq:WidgetCollection">
<test
jcr:primaryType="cq:Widget"
fieldLabel="Test"
xtype="textfield"/>
<file-upload
jcr:primaryType="cq:Widget"
dialogTitle="the dialog title"
fieldLabel="the field label"
text="the text"
xtype="fileuploaddialogbutton"/>
</items>
</files>
</items>
</tab1>
</items>
</items>
Can anyone explain how to have reCaptcha functionality like stackoverflow in my MVC3 application.
And how can you customize that?
I use the Google ReCaptcha and it works very well and is very simple to implement.
Note that if you are using Https be sure you have the current version of the dll (1.0.5.0 at this time)
You need to create an account on the Google Recaptcha site and get a set of public and private keys. Add the keys to your web project main web.config file:
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="ReCaptchaPrivateKey" value="put your private key value here" />
<add key="ReCaptchaPublicKey" value="put your public key value here" />
</appSettings>
Now use NuGet and install the reCAPTCHA plugin for .NET
Then, go to your web.config file inside of your VIEWS folder. Add this line:
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Recaptcha"/>
</namespaces>
Then, in your view that you want to show the captcha, add the using statement at the top of your file
#using Recaptcha;
then add this to your view:
<div class="editor-label">
Are you a human?
</div>
<div class="editor-field">
#Html.Raw(Html.GenerateCaptcha("captcha", "clean"))
#Html.ValidationMessage("captcha")
</div>
In your controller action you will need to modify the signature to accept the captcha results:
[HttpPost]
[RecaptchaControlMvc.CaptchaValidator]
public ActionResult ForgotPassword(CheckUsernameViewModel model, bool captchaValid, string captchaErrorMessage) {
if (!Membership.EnablePasswordReset)
throw new Exception("Password reset is not allowed\r\n");
if(ModelState.IsValid) {
if(captchaValid) {
return RedirectToAction("AnswerSecurityQuestion", new { username = model.Username });
}
ModelState.AddModelError("", captchaErrorMessage);
}
return View(model);
}
Following those steps have allowed me to implement captcha on several pages and it works smoothly. Note that the parameter names on the controller action MUST BE NAMED CORRECTLY:
bool captchaValid, string captchaErrorMessage
If you changed these parameter names you WILL get an error at runtime when your form posts back to the controller action.
I would recommend using a Honeypot Captcha. The experience for your users is MUCH better. There is one fore ASP.NET MVC here http://nuget.org/packages/SimpleHoneypot.MVC
PM> Install-Package SimpleHoneypot.MVC4
There is a WiKi on how to get it up here: https://github.com/webadvanced/Honeypot-MVC/wiki
Just start out with the Getting Started section.
You can read more about the general idea of a Honeypot Captcha here: http://haacked.com/archive/2007/09/11/honeypot-captcha.aspx
I can't figure this one out.
I have the following SiteMap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/" title="Root" description="Go root">
<siteMapNode url="~/h" title="Home" description="Go home" />
<siteMapNode url="~/h/uo" title="Ultima Online" description="Ultima Online">
<siteMapNode url="~/h/uo/get" roles="RegisteredUser" title="Get account!" description="Get account!" />
</siteMapNode>
</siteMapNode>
</siteMap>
I've an XmlSiteMapProvider with securityTrimmingEnabled="true", which points to this site map file.
The file I want to trim has an authorization rule in it's folder's web.config
<configuration>
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
The file can't be accessed via url, if I type http://localhost/h/uo/get I get redirected to login page.
I've set up an <asp:Menu> like this in the Master page file:
<asp:SiteMapDataSource ID="MenuSiteMap" ShowStartingNode="false"
SiteMapProvider="MenuSiteMapProvider" runat="server"
/>
<div>
<asp:Menu ID="NavigationMenu" runat="server" DataSourceID="MenuSiteMap"
CssClass="menu" EnableViewState="false"
IncludeStyleBlock="false" Orientation="Horizontal"
/>
</div>
Yet, when the page is rendered, I see the Get account node that is supposed to be trimmed when I'm not even logged in, no matter what.
What am I doing wrong?
Is there any other way to build a security trimming enabled site map navigation menu?
I'm using ASP.NET 4.0, and URL-rewritting with an HttpModule.
In reading http://forums.asp.net/t/975077.aspx/1 I found out that this is exactly what is happening to me.
If the node doesn't have an URL it behaves fine, but if it does, like all of my nodes do. Security trimming is just ignored.
I resolved my problem by resorting to a more intuitive role based site map implementation, to say:
public class TrimmingXmlSiteMapProvider : XmlSiteMapProvider
{
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
if (node.Roles.Cast<string>().Any(r => r == "*"))
return true;
if (node.Roles.Count > 0 && node.Roles.Cast<string>().Count(Roles.IsUserInRole) == 0)
return false;
return node.ParentNode != null && node.ParentNode.IsAccessibleToUser(context);
}
}
Then, the only change I had to make was add an asterisk to the root level's role definition.
How does this work?
First I check if any of the roles definied for this node is an asterisk, if that's the case, then I can see the node.
Second, if the node isn't everyone-level, I check if there are any roles specified, and if the logged in user is part of at least one of them.
Lastly, I check if there is a parent node, and just inherit their rule.
This allows the security trimming to actually be "SECURITY TRIMMING" and not well, however the heck it's supposed to be working by default.
I have a sitemap that has a link for when a user is not logged in, but when they do login, the link should change, for example, nonmember.aspx should change to member.aspx. This sitemap is tied to an asp:menu. Does anyone know how to do this?
A simple solution is to have two nodes in your sitemap.
One node shows up for Anonymous users.
One node shows up for Authenticated users with the security access
I believe you can set this up quite simply.
The end result is the same as changing the link but it's easier to maintain.
To add to this:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode title="Home" url="~/" roles="*">
<siteMapNode url="~/Member.aspx" title="Home" roles="SpecialPeople" />
<siteMapNode url="~/Nonmember.aspx" title="Site Map" roles="HideForUsers" />
</siteMapNode>
</siteMap>
So, you set up a rule that denies access to the "HideForMembers" role to authenticated users. It's something like that. ASP.NET will take the first rule it finds a match, so you should be able to accomplish it this way.
Otherwise, you could do a Menu_OnDataBound and look for the node:
Protected Sub menMainDataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Dim myPage As New Page
Dim myPrincipal As IPrincipal
Dim colNodes As New Collection
myPrincipal = myPage.User
If myPrincipal.Identity.IsAuthenticated = True Then
Dim menNode As MenuItem
For Each menNode In menMain.Items
Select Case menNode.Value.ToString
Case "Products"
colNodes.Add(menNode)
Case "Contact Us"
colNodes.Add(menNode)
Case "About Us"
colNodes.Add(menNode)
Case "Links"
colNodes.Add(menNode)
End Select
Next
For Each menNode In colNodes
menMain.Items.Remove(menNode)
Next
End If
Catch ex As Exception
End Try
End Sub
source
The below is the web.config code you're looking for:
<location path="Registration.aspx">
<system.web>
<authorization>
<allow users="?" />
<deny users="*" />
</authorization>
</system.web>
</location>